package com.le.tester.leetcode;

/**
 * createTime：2021/8/23 15:27
 * description：位1的个数
 */
public class HammingWeight {
    public int hammingWeight(int n) {
        String s = Integer.toBinaryString(n);
        int length = s.length();
        int result = 0;
        for (int i = 0; i < length; i++) {
            if (49 == s.charAt(i)) {
                result++;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(new HammingWeight().hammingWeight(00000000000000000000000000001011
        ));
    }
}
